/**
 * Created by dongp on 2016/5/12.
 */

$(function(){
    $(".showA").on("mouseover",function(){
        $(this).children("ul").show();
    });
    $(".showA").on("mouseout",function(){
        $(this).children("ul").hide();
    });

    // 使用新地址绑定点击事件
    $(".newAddressBtn").on("click",function(){
        $("#addressDiv").toggle();
    });

    // 数量减一
    $("#substract").on("click",function(){
        var value = new Number($("#quantity").val());
        if(value < 1) {
            value = 0;
        }else{
            value = value-1;
        }
        $("#quantity").val(value);
        caltotal();
    });

    // 数量加一
    $("#add").on("click",function(){
        var value = new Number($("#quantity").val());
        value = value+1;
        $("#quantity").val(value);
        caltotal();
    });

    caltotal();
});

function caltotal(){
    var up = new Number($("#up").html());
    var rb = new Number($("#rb").html());
    var count = new Number($("#quantity").val());
    var total = up*count - rb;
    $("#totalMoney").html(total.toFixed(1));
}

